import jsYaml, { Type } from "js-yaml";

export type YAMLUniverseType = {
  // 组ID
  groupID: number;

  // 图标ID
  iconID: number;

  // 市场组ID
  marketGroupID: number;

  // 质量
  mass: number;

  // 元组ID
  metaGroupID: number;

  // 名称
  name: {
    // 中文名称
    zh: string;
  };

  // 部分大小
  portionSize: number;

  // 是否发布
  published: boolean;

  // 半径
  radius: number;

  // 体积
  volume: number;
};

export type YAMLUniverseTypeMap = Record<number, YAMLUniverseType>;
export const YAMLUniverseTypeSchema = jsYaml.DEFAULT_SCHEMA.extend([
  new Type("!YAMLUniverseTypeMap", {
    kind: "mapping",
    construct: (data: YAMLUniverseType) => {
      // 将适当字段解析为数字
      data.groupID = Number(data.groupID);
      data.iconID = Number(data.iconID);
      data.marketGroupID = Number(data.marketGroupID);
      data.mass = Number(data.mass);
      data.metaGroupID = Number(data.metaGroupID);
      data.portionSize = Number(data.portionSize);
      data.radius = Number(data.radius);
      data.volume = Number(data.volume);

      // 将发布字段解析为布尔值
      data.published = Boolean(data.published);

      return data;
    },
    instanceOf: Object,
    represent: (data: any) => data,
  }),
]);
